home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
embedded
/
mcu332
/
332doc.arc
/
332BUGC3
< prev
next >
Wrap
Text File
|
1989-12-19
|
20KB
|
556 lines
DEBUG MONITOR USER'S MANUAL MOTOROLA
4-1 M68332BUG
DEBUG MONITOR USER'S MANUAL MOTOROLA
M68332BUG 4-1
CHAPTER 4
USING THE ONE-LINE ASSEMBLER/DISASSEMBLER
4.1 INTRODUCTION
Included as part of the 332Bug firmware is a one-line assembler/disassembler function. The
assembler is an interactive assembler/editor in which the source program is not saved. Each
source line is translated into MC68332 machine language code and is stored line-by-line into
memory as it is entered. In order to display an instruction, the machine code is disassembled
and the instruction mnemonic and operands are displayed. All valid MC68332 instructions
are translated.
The 332Bug assembler is effectively a subset of the MC68332 resident structured assembler.
It has some limitations as compared with the resident assembler, such as not allowing line
numbers and labels; however, it is a powerful tool for creating, modifying, and debugging
MC68332 code.
4.1.1 MC68332 Assembly Language
MC68332 assembly language is the symbolic language used to code source programs for
processing by the assembler. This language is a collection of mnemonics representing:
Ñ Operations
MC68332 machine-instruction operation code
Directives (pseudo-ops)
Ñ Operators
Ñ Special symbols
4.1.1.1 Machine-Instruction Operation Codes. The part of the assembly language
that provides the mnemonic machine-instruction operation codes for the MC68332 machine
instructions are described in the CPU32 Reference Manual. Refer to that manual for any
questions concerning operation codes.
4.1.1.2 Directives. Normally, assembly language can contain mnemonic directives
which specify assembler auxiliary action. The 332Bug assembler recognizes only two
directives: DC.W (define constant) and SYSCALL. These two directives define data within
the program and make 332Bug utility calls (refer to paragraphs 4.2.3 and 4.2.4, respectively).
4.1.2 MC68332 Resident Structured Assembler Comparison
There are several major differences between the 332Bug assembler and the MC68332
resident structured assembler. The resident assembler is a two-pass assembler that
processes an entire program as a unit, while the 332Bug assembler processes each line of a
program as an individual unit. Due mainly to this basic functional difference, the 332Bug
assembler capabilities are more restricted:
Ñ Label and line numbers are not used. Labels are used to reference other lines and
locations in a program. The one-line assembler has no knowledge of other lines
and, therefore, cannot make the required association between a label and the label
definition located on a separate line.
Ñ Source lines are not saved. In order to read back a program after it is entered, the
machine code is disassembled and then displayed as mnemonics and operands.
Ñ Only two directives (DC.W and SYSCALL) are accepted.
Ñ No macro operation capability is included.
Ñ No conditional assembly is used.
Ñ No structured assembly is used.
Ñ Several symbols recognized by the resident assembler are not included in the
332Bug assembler character set. These symbols include ''>'' and ''<''. Three other
symbols have multiple meaning to the resident assembler, depending on the context.
These are:
Asterisk (*) - Multiply or current PC
Slash (/) - Divide or delimiter in a register list
Ampersand (&) - And or decimal number prefix
Although functional differences exist between the two assemblers, the one-line assembler is
a true subset of the resident assembler. The 332Bug assembler format and syntax are
acceptable to the resident assembler except as described above.
4.2 SOURCE PROGRAM CODING
A source program is a sequence of source statements arranged in a logical manner to
perform predetermined tasks. Each source statement occupies a line and must be either an
executable instruction, a DC.W directive, or a SYSCALL assembler directive. Each source
statement follows a consistent source line format.
4.2.1 Source Line Format
Each source statement is a combination of operation and, as required, operand fields. Line
numbers, labels and comments are not used.
4.2.1.1 Operation Field. Since there is no label field, the operation field may begin in
the first available column. It may also follow one or more spaces. Entries can consist of one
of three categories:
Ñ Operation codes which correspond to the MC68332 instruction set.
Ñ Define constant directive (DC.W) defines a constant in a word location.
Ñ System call directive (SYSCALL) calls 332Bug system utilities.
The size of the data field affected by an instruction is determined by the data size codes.
Some instructions and directives can operate on more than one data size. For these
operations, the data size code must be specified or a default size applicable to the instruction
is used. The size code need not be specified if only one data size is permitted by an
operation. The operation field is followed by a period (.) and the data size code. The data
size codes are:
B = Byte (8-bit data)
W = Word (16-bit data; the usual default size)
L = Longword (32-bit data)
When the instruction or directive does not have a data size attribute, the data size code is not
permitted.
EXAMPLES: Legal
LEA (A0),A1 Load the effective address of the first operand into A1. The
longword size is the default (.B, .W not allowed) for this
instruction
ADD.B (A0),D0 Add the byte pointed to in A0 to the lowest order byte in D0.
ADD D1,D2 Add the low order word of D1 to the low order word of D2. W is
the default size code for ADD.
ADD.L A3,D3 Add the entire 32-bit (longword) contents of A3 to D3.
EXAMPLE: Illegal:
SUBA.B #5,A1 Illegal size specification (.B not allowed in instruction SUBA).
This instruction would have subtracted the value 5 from the low
order byte of A1; byte operations on address registers are not
allowed.
4.2.1.2 Operand Field. If present, the operand field follows the operation field and is
separated from the operation field by at least one space. When two or more operand
subfields appear within a statement, separate them with a comma. In an instruction like 'ADD
D1,D2', the first subfield (D1) is called the source effective address (<EA>) field, and the
second subfield (D2) is called the destination <EA> field. Thus, the contents on D1 are
added to the contents of D2 and the result saved in register D2. In the instruction 'MOVE
D1,D2', the first subfield (D1) is the source field and the second subfield (D2) is the
destination field. In other words, for most two-operand instructions, the format '<opcode>
<source>,<destination>' applies.
4.2.1.3 Disassembled Source Line. The disassembled source line may not look
identical to the source line entered. The disassembler decides how to interpret the numbers
used. If the number is an offset of an address register, it is treated as a signed hexadecimal
offset. Otherwise, it is treated as a straight unsigned hexadecimal.
EXAMPLE:
MOVE.L #1234,5678
MOVE.L FFFFFFFC(A0),5678
disassembles to
00003000 21FC0000 12345678 MOVE.L #$1234,($5678).W
00003008 21E8FFFC 5678 MOVE.L -$4(A0),($5678).W
Also, for some instructions, there are two valid mnemonics for the same opcode, or there is
more than one assembly language equivalent. When the opcode is disassembled some
instructions may appear different from the originally entered code. As examples:
BT is dissembled as BRA
DBRA is dissembled as DBF
NOTE
The assembler recognizes two forms of mnemonics for two branch instructions.
The BT form (branch conditionally true) has the same opcode as the BRA
instruction. Also, DBRA (decrement and branch always) and DBF (never true,
decrement, and branch) mnemonics are different forms for the same instruction.
In each case, the assembler accepts both forms.
4.2.1.4 Mnemonics and Delimiters. The assembler recognizes all MC68332
instruction mnemonics. Numbers are recognized as binary, octal, decimal, and hexadecimal,
with hexadecimal as the default case.
Ñ Decimal values are preceded by an ampersand (&). Examples are:
&12334
-&987654321
Ñ Hexadecimal values are preceded by a dollar sign ($). An example is:
$AFE5
One or more ASCII characters enclosed by single quote marks ( ' ) constitute an ASCII string.
ASCII strings are right-justified and zero filled (if necessary), whether stored or used as
immediate operands.
00003000 21FC0000 12345678 MOVE.L #$1234,($5678).W
005000 0053 DC.W 'S'
005002 223C41424344 MOVE.L #'ABCD',D1
005008 3536 DC.W '56'
The following register mnemonics are recognized/referenced by the
assembler/disassembler:
Pseudo Registers
R0-R7 User Offset Registers.
Main Processor Registers
PC Program Counter - Used only in forcing program counter-relative
addressing.
SR Status Register
CCR Condition Codes Register (Lower eight bits of SR)
USP User Stack Pointer
SSP System Stack Pointer
Main Processor Registers (cont'd)
VBR Vector Base Register
SFC Source Function Code Register
DFC Destination Function Code Register
D0-D7 Data Registers
A0-A7 Address Registers - Address register A7 represents the active system
stack pointer, that is, either USP or SSP, as specified by the S bit of the
status register
4.2.1.5 Character Set. The character set recognized by the 332Bug assembler is a
subset of ASCII and listed below:
Ñ The letters A through Z (uppercase and lowercase)
Ñ The integers 0 through 9
Ñ Arithmetic operators: +, -, *, /, <<, >>, !, &
Ñ Parentheses ( )
Ñ Characters used as special prefixes:
# (pound sign) specifies the immediate form of addressing.
$ (dollar sign) specifies a hexadecimal number.
& (ampersand) specifies a decimal number.
@ (commercial at sign) specifies an octal number.
% (percent sign) specifies a binary number.
' (apostrophe) specifies an ASCII literal character string.
Ñ Five separating characters:
Space
. (period)
/ (slash)
- (dash)
Ñ The asterisk (*) character indicates current location.
4.2.2 Addressing Modes
Effective address modes, combined with operation codes, define the particular function
performed by a given instruction. Effective addressing and data organization are described
in detail in the CPU32 Reference Manual.
Table 4-1 summarizes the 332Bug one-line assembler addressing modes.
TABLE 4-1. 332Bug Assembler Addressing Modes
FORMAT DESCRIPTION
Dn Data register direct
An Address register direct
(An) Address register indirect
(An)+ Address register indirect with post-increment
-(An) Address register indirect with pre-decrement
d(An) Address register indirect with displacement
d(An,Xi) Address register indirect with index, 8-bit displacement
(bd,An,Xi) Address register indirect with index, base displacement
ADDR(PC) Program counter indirect with displacement
ADDR(PC,Xi) Program counter indirect with index, 8-bit displacement
(ADDR,PC,Xi) Program counter indirect with index, base displacement
(xxxx).W Absolute word address
(xxxx).L Absolute long address
#xxxx Immediate data
The user may use an expression in any numeric field of these addressing modes. The
assembler has a built in expression evaluator that supports the following operand types and
operators:
Binary numbers (%10 )
Octal numbers (@76543210)
Decimal numbers (&9876543210)
Hexadecimal numbers ($FEDCBA9876543210)
String literals ('CHAR' )
Offset registers (R0-R7)
Program counter (*)
Allowed operators are:
Addition +
Subtraction -
Multiply *
Divide /
Shift left <<
Shift right >>
Bitwise or !
Bitwise and &
The order of evaluation is strictly left to right with no precedence granted to some operators
over others. The only exception is when the user forces the order of precedence via the use
of parentheses.
Possible points of confusion:
Ñ Differentiate numbers and registers to avoid confusion. For example:
CLR D0 means CLR.W register D0. On the other hand,
CLR $D0
CLR 0D0
CLR +D0
CLR D0+0 all mean CLR.W memory location $D0.
Ñ With the use of asterisk (*) to represent both multiply and program counter,
how does the assembler know when to use which definition?
For parsing algebraic expressions, the order of parsing is
<OPERAND> <OPERATOR> <OPERAND> <OPERATOR>
with a possible left or right parenthesis.
Given the above order, the assembler can distinguish by placement
which definition to use. For example:
*** Means PC * PC
*+* Means PC + PC
2** Means 2 * PC
*&&16 Means PC AND &16
When specifying operands, the user may skip or omit entries with the following addressing
modes.
Ñ Address register indirect with index, base displacement.
Ñ Program counter indirect with index, base displacement.
For the above modes, the rules for omission/skipping are as follows:
Ñ The user may terminate the operand by specifying '')''.
EXAMPLE:
CLR ( ) or
CLR (,,) is equivalent to
CLR (0.N,ZA0,ZD0.W*1)
Ñ The user may skip a field by stepping past it with a comma.
EXAMPLE:
CLR (D7) is equivalent to
CLR ($D7,ZA0,ZD0.W*1)
but
CLR (,,D7) is equivalent to
CLR (0.N,ZA0,D7.W*1)
Ñ If the user does not specify the base register, the default is ''ZA0''. When Z precedes
the register number, it indicates that register is suppressed.
Ñ If the user does not specify the index register, the default is ''ZD0.W*1''.
Ñ Any unspecified displacements are defaulted to ''0''.
4.2.3 Define Constant Directive (DC.W)
The format for the DC.W directive is:
DC.W <operand >
This directive defines a constant in memory. The DC.W directive has only one operand (16-
bit value) which can contain the actual value (decimal, hexadecimal, or ASCII). Alternatively,
the operand can be an expression which is assigned a numeric value by the assembler. The
constant is aligned on a word boundary if word (.W) size is specified. An ASCII string is
recognized when characters are enclosed inside single quotes marks (' . . . '). Each
character (7 bits) is assigned to a byte of memory with the eighth bit (MSB) always equal to
zero. If only one byte is entered, the byte is right justified. A maximum of two ASCII
characters may be entered for each DC.W directive.
EXAMPLES:
00010022 04D2 DC.W 1234 Decimal number
00010024 AAFE DC.W &AAFE Hexadecimal number
00010026 4142 DC.W 'AB' ASCII String
00010028 5443 DC.W 'TB'+1 Expression
0001002A 0043 DC.W 'C' ASCII character is right justified
4.2.4 System Call Directive (SYSCALL)
This directive aids the user in making the TRAP #15 calls to the system functions. The format
for this directive is:
SYSCALL <function name >
For example, the following two pieces of code produce identical results.
TRAP #$F
DC.W 0
or
SYSCALL .INCHR
Refer to Chapter 5 (SYSTEM CALLS), for a complete listing of all the functions provided.
4.3 ENTERING AND MODIFYING SOURCE PROGRAM
User programs are entered into memory using the one-line assembler/disassembler. The
program is entered in assembly language statements on a line-by-line basis. The source
code is not saved as it is converted immediately upon entry into machine code. This imposes
several restrictions on the type of source line that can be entered.
Symbols and labels, other than the defined instruction mnemonics, are not allowed. The
assembler has no means of storing the associated values of the symbols and labels in
lookup tables. This forces the programmer to use memory addresses and to enter data
directly rather than use labels.
Also, editing is accomplished by retyping an entirely new source line. Add or delete lines by
moving a block of memory data to free up or delete the appropriate number of locations (refer
to the BM command).
4.3.1 Executing the Assembler/Disassembler
The assembler/disassembler is actuated using the ;DI option of the MM (Memory Modify) and
MD (Memory Display) commands:
MM <ADDR >;DI
where
<CR> sequences to next instruction
.<CR> exits command
and
MD[S] <ADDR>[:<count>I<ADDR>];DI
Use the MM (;DI option) to enter and modify the program. When this command is used, the
memory contents at the specified location are disassembled and displayed. A new or
modified line can be entered if desired.
The disassembled line is either an MC68332 instruction, a SYSCALL, or a DC.W directive. If
the disassembler recognizes a valid form of an instruction, the instruction is returned. If the
disassembler does not recognizes a valid form of an instruction, random data occurs, the
DC.W $XXXX (always hex) is returned. Because the disassembler gives precedence to
instructions, a word of data interpreted as a valid instruction is returned as the instruction.
4.3.2 Entering a Source Line
Enter a new source line immediately following the disassembled line. Use the format
discussed in paragraph 4.2.1.
332Bug>MM 6000;DI <CR>
00006000 2600 MOVE.L D0,D3 ? ADDQ.L #1,A3 <CR>
When a line is terminated with a carriage return, the old source line is erased from the
terminal screen, the new line is assembled and displayed, and the next instruction in memory
is disassembled and displayed:
332Bug>MM 6000;DI<CR>
00006000 528B ADDQ.L #1,A3
00006002 4282 CLR.L D2 ?
If a hardcopy terminal is used, configure port 0 for hardcopy mode (refer to the PF command).
In hardcopy mode the above example looks like:
332Bug>MM 6000;DI<CR>
00006000 2600 MOVE.L D0,D3 ? ADDQ.L #1,A3<CR>
00006000 528B ADDQ.L #1,A3
00006002 4282 CLR.L D2 ?
Another program line can now be entered. Program entry continues in like manner until all
lines have been entered. A period (.) is used to exit the MM command. If an error occurs
during line assembly, the assembler displays the line unassembled with an error message.
The location being accessed is redisplayed:
332Bug>MM 6000;di <CR>
00006000 528B ADDQ.L #$1,A3? LEA.L 5(A0,D8),A4<CR>
LEA.L 5(A0,D8),A4
BAD COMBINATION OF COMMAND, OPERANDS
00006000 528B ADDQ.L #$1,A3?
4.3.3 Entering Branch and Jump Addresses
When entering a source line containing a branch instruction (BRA, BGT, BEQ, etc) do not
enter the offset to the branch's destination in the instruction operand field. The offset is
calculated by the assembler. The user must append the appropriate size extension to the
branch instruction.
To reference a current location in an operand expression use the asterisk (*) character.
EXAMPLES:
0000D000 6000BF68 BRA *-4096
0000D000 60FE BRA.B *
0000D000 4EF90000 D000 JMP *
0000D000 4EF00130 0000D000 JMP (*,A0,D0)
In the case of forward branches or jumps, the absolute address of the destination may be
unknown as the program is being entered. The user may enter an asterisk (*) for branch to
self in order to reserve space. After the actual address is discovered, the line containing the
branch instruction can be re-entered using the correct value. Enter branch sizes ''B'' or ''W'',
as opposed to ''S'' and ''L''.
4.3.4 Assembler Output/Program Listings
Use the MD (Memory Display) command with the ;DI option to obtain a listing of the program.
The MD command requires the starting address and a line count or ending address to be
entered in the command line. When the ;DI option is executed with a line count, the number
of instructions disassembled and displayed is equal to the line count.
Note again, that the listing may not correspond exactly to the program as entered. As
discussed in paragraph 4.2.1.3, the disassembler displays in signed hexadecimal any
number it interprets as an offset of an address register; all other numbers are displayed in
unsigned hexadecimal.